In [1]:
%matplotlib inline
from ggplot import *
Facets allow you to visualize high-dimensional data quickly and (most of the time) easily. Faceting splits your data up into differnet subgroups based upon different variables.
We're going to be using the diamonds dataset in these examples. It might be helpful to refresh yourself with the dataset before jumping into the samples.
In [2]:
diamonds.head()
Out[2]:
In [3]:
ggplot(diamonds, aes(x='carat', y='price')) + geom_point() + facet_grid('clarity')
Out[3]:
In [4]:
ggplot(diamonds, aes(x='carat', y='price')) + geom_point() + facet_grid(None, 'clarity')
Out[4]:
In [5]:
ggplot(diamonds, aes(x='carat', y='price')) + geom_point() + facet_wrap('clarity')
Out[5]:
In [6]:
ggplot(diamonds, aes(x='carat', y='price')) + geom_point() + facet_wrap('clarity', ncol=4)
Out[6]:
In [7]:
ggplot(diamonds, aes(x='carat', y='price')) + geom_point() + facet_wrap('clarity', 'cut')
Out[7]:
In [8]:
ggplot(diamonds, aes(x='carat', y='price', shape='cut', color='clarity')) + \
geom_point() + \
scale_color_brewer(type='qual') + \
facet_grid('color')
Out[8]:
In [9]:
ggplot(diamonds, aes(x='carat', y='price', color='depth')) + \
geom_point() + \
scale_color_gradient(low='white', high='black') + \
facet_grid('color', 'clarity')
Out[9]:
In [ ]: